<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Proxy</title>
</head>
<body>
    <div id="app">
        hello
    </div>
    <script>
      // 模拟 Vue 中的 data 选项
      let data = {
        msg: 'hello',
        count: 0
      }
      let vm = new Proxy(data,{
        get(target, key) {
          console.log('get, key: ', key, target[key])
          return target[key]
        },
        set(target, key, newValue) {
          console.log('set, key: ', key, newValue)
          if (target[key]===newValue){ return }
          target[key]=newValue;
          document.querySelector('#app').textContent = target[key]
        }
      })
      // 测试
      vm.msg = 'Hello World'
      console.log(vm.msg)
    </script>
</body>
</html>
